import ThreeApp from './ThreeApp';
import View2D from './View2D';

export default class ViewManager {
  public constructor() {}
  private viewObjects: View2D[] = [];

  public getAllViewObjects(): View2D[] {
    return this.viewObjects.slice();
  }

  public addViewObject(obj: View2D): boolean {
    if (!this.viewObjects.includes(obj)) {
      this.viewObjects.push(obj);
      ThreeApp.scene.add(obj);
    }
    return true;
  }

  public removeViewObject(obj: View2D) {
    const index = this.viewObjects.indexOf(obj);
    if (index >= 0) {
      this.viewObjects.splice(index, 1);
      ThreeApp.scene.remove(obj);
    }
  }
}
